package com.hanserwei.community.enums;

import org.jetbrains.annotations.Nullable;

public enum UserRoleEnum {
    ADMIN("管理员", 1),
    USER("普通用户", 2);

    private final String roleName;
    private final Integer roleId;

    UserRoleEnum(String roleName, Integer roleId) {
        this.roleName = roleName;
        this.roleId = roleId;
    }


    public static @Nullable String getRoleName(Integer roleId) {
        for (UserRoleEnum value : UserRoleEnum.values()) {
            if (value.roleId.equals(roleId)) {
                return value.roleName;
            }
        }
        return null;
    }

    public static @Nullable Integer getRoleId(String roleName) {
        for (UserRoleEnum value : UserRoleEnum.values()) {
            if (value.roleName.equals(roleName)) {
                return value.roleId;
            }
        }
        return null;
    }
}
